package com.reader;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;

import com.util.LogUtil;

public class FileHandler {

	int lestLength = 0;
	private List<String> errorCodes = LogUtil.getErrorCodes();
	private File file;
	private FileInputStream fstream;

	public FileHandler(String path) {
		file = new File(path);
		try {
			fstream = new FileInputStream(file);

		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public FileHandler(File file) {
		this.file = file;
		try {
			fstream = new FileInputStream(file);

		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	public String readLog() {
		int fileLen = (int) file.length();
		int size = fileLen - lestLength;
		byte[] b = new byte[size];

		try {
			fstream.read(b, lestLength, fileLen);
			return new String(b);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "ERROR : reading file";
	}

}
